package com.joke.auto;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jdbc.mysql.MysqlLocalConnect;
import com.jdbc.mysql.MysqlServerConnect;
import com.joke.oss.UploadSimple;

public class JokeFetch {
	// 日志输出
	private static final Logger logger = LoggerFactory.getLogger(JokeFetch.class);
	public String fetch() {
		boolean server = MysqlServerConnect.confirmConnect();
		if(server) {
			logger.info("-server端数据库可用-");
		}else {
			logger.error("->Failure to connect the server database<-");
			return "Failure to connect the server database";
		}
		
		boolean local = MysqlLocalConnect.confirmConnect();
		if(local) {
			logger.info("-local数据库可用-");	
		}
		else {
			logger.error("->Failure to connect the local database<-");
			return "Failure to connect the local database";
		}
		
		boolean oss = UploadSimple.confirmOSS();
		if(oss) {
			logger.info("-OSS服务器可用-");
		}else {
			logger.error("->Failure to connect the OSS Server<-");
			return "Failure to connect the OSS Server";
		}
		
		if(server&&local&&oss) {
			logger.info("--开始抓取笑话内容--");
			new FetchTxT().fetch();
			new FetchHot().fetch();
			new FetchImage().fetch();
			new FetchVideo().fetch();
			logger.info("--结束抓取笑话内容--");
			logger.info("--开始上传媒体(图片)到OSS--");
			UploadSimple.uploadOSS();
			logger.info("--结束上传媒体(图片)到OSS--");
		}
		return "Success";
	}

}
